package pl.enigmatic.parser.markup;

import java.util.regex.Pattern;

import pl.enigmatic.parser.string.ArrayConverter;


public class MarkupProperties extends pl.enigmatic.math.OrderedMap.VectorImpl<String, String> {

	private final static ArrayConverter<String[]> converter = new ArrayConverter<String[]>(String[].class, new ArrayConverter<String>(String.class,
			Pattern.compile(" += +"), "="), ArrayConverter.COMMA_PATTERN, ArrayConverter.COMMA_SEPARATOR);

	public static MarkupProperties parseString(final String properties) {
		final String[][] values = converter.convert(properties);
		final MarkupProperties res = new MarkupProperties(values.length > 0 ? values[0][0] : null);
		for (int i = 1; i < values.length; i++) {
			res.put(values[i][0], values[i][1]);
		}
		return res;
	}

	private final String mainValue;

	public MarkupProperties(final String mainValue) {
		this.mainValue = mainValue;
	}

	public String getMainValue() {
		return mainValue;
	}

	/** */
	private static final long serialVersionUID = 1L;

	@Override
	public String toString() {
		return getClass().getSimpleName() + " [" + (mainValue != null ? "mainValue=" + mainValue + ", " : "")
				+ (super.toString() != null ? "map=" + super.toString() : "") + "]";
	}

}
